<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 部门管理</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="css/public.css" rel="stylesheet" type="text/css">
	<link href="css/index.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	
	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/deptService.js"></script>
</head>

<body oncontextmenu='return false'>

<%@include file="/WEB-INF/jsp/include/head.jsp"%>

<div class="wrap100">

	<%@include file="/WEB-INF/jsp/include/left.jsp"%>	

	<!--right begin-->
    <div class="fl right">
 
 			<div class="full">
    
    		<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>部门快速搜索</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>                
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
            <form action="<%=basePath%>trade/deptList" method="GET">
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
                <td>部门名称：                </td>
                <td><input size="25" class="input" type="text" name="deptName" value="${searchCond.deptName}"/>
                </td>
                <td>
                	<input type="submit" style="background:url(images/search.gif);width:92px;height:25px;border:0;margin:0;" value="" />
                </td>
              </tr>
            </table>
            </form>
      </div>
      
    		<!--人员分配 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>部门名称</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightPropertyList">
            	<div class="title1">
                <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#dfe5e9">                  
                  <tr>
                    <th width="4%" align="left"><input type="checkbox" name="allSelectId" id="allSelectId" onclick="judgmentChecjBox('allSelectId','id')" /></th>
                    <th width="24%" align="left">部门编号</th>
                    <th width="24%" align="left">部门名称</th>
                    <th width="24%" align="left">部门排序</th>
                    <th width="24%" align="left">部门职能</th>                    
                  </tr>
                </table>
              </div>
                <div class="list">
                <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#dfe5e9">
                  <c:forEach var="dept" items="${deptList}">
                  <tr>
                    <td width="4%" align="left"><input type="checkbox" value="${dept.id}" name="id" /></td>
                    <td width="24%" align="left">${dept.id}</td>
                    <td width="24%" align="left">${dept.deptName}</td>
                    <td width="24%" align="left">${dept.orderNo}</td>
                    <td width="24%" align="left">${dept.detail}</td>
                  </tr>
                  </c:forEach>
              </table>
              </div>
            </div>
            <!--人员分配 end-->


            <!--统计 end-->
            <div class="total">
                <div class="fl Statistics">总数：<strong>${searchStat.totalCount} </strong> 条
                <script type="text/javascript">
				var pageControl = new wpagebar('pageControl');
				pageControl.argName = "pageIndex";
				pageControl.pageCount = ${searchStat.pageCount};
				pageControl.load();
				</script>
                </div>
                <div class="fr Operating">                
                    <ul>
                        <li><input name="添 加" type="button" class="button" value="添 加" onclick="addDept()"/></li>
                        <li><input name="修 改" type="button" class="button" value="修 改" onclick="editDepts()"/></li>
                        <li><input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultiple()"/></li>                        
                    </ul>               
                
                </div>
            </div>
 
            <!--统计 end-->
            
    </div>
	<!--right end-->
    <div id="win_temp" style="display:none">
	  	<div id="winCon_1"  >
			<table class="tabView" style="margin-top:5px">
				<tr><th width="100">部门名称：</th>
					<td><input type="text" name="deptName0" id="deptName0" value="" maxlength="100" style="width:200px"/>
						<input type="hidden" name="dpId0" id="dpId0" value="" /></td>
				</tr>
				<tr><th>部门职能：</th><td><textarea name="detail0" id="detail0" rows="4" cols="25"></textarea> </td></tr>
				<tr><th>排序：</th><td><input type="text" name="orderNo0" id="orderNo0" value="99"></td></tr>
				<tr><td colspan="2" style="text-align:center;height:"><input type="button" value=" 提 交 " class="btn1" onclick="submitDept()"/></td></tr>
			</table>
		</div>
  	</div>
  	
</div>  
    <script src="<%=basePath%>js/win.js" type="text/javascript"></script>
    
</div>

<%@include file="/WEB-INF/jsp/include/bottom.jsp"%>
<script  type="text/javascript">
	function addDept(){
		WIN.show('<font size=5>添加部门</font>',$('winCon_1'),{height:250});
	}
	function editDept(id){
		WIN.show('<font size=5>修改部门</font>',$('winCon_1'),{height:250});
		deptService.getDepartmentById(id,function(data){
			$('dpId0').value=data.id;
			$('deptName0').value=data.deptName;
			$('detail0').value=data.detail;
			$('orderNo0').value=data.orderNo;
		})
	}
	function delDept(id){
		if(confirm("删除部门，将删除部门下的人员,确定删除 ？")){
			WIN.showpg();
			deptService.deleteDepartment(id,{
				callback:function(f){WIN.closepg();alert("删除成功");reload();},
				exceptionHandler:function(message){WIN.closepg();alert(message);alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
	function delsellMultiple(){			
		var objs = document.getElementsByName("id");
		var ids='';	
		for(var i=0;i<objs.length;i++){
			if(objs[i].checked){
				ids+=objs[i].value+",";
			}
		}
		if(ids==''){
			alert("请先选择要操作的信息");
			return ;
		}
		ids = ids.substring(0,ids.length - 1);
		
		if(confirm("您确定要删除?")){
			if(ids == ""){
				alert("请先选择要删除的信息！");
				return false;
			}else{
				deptService.deleteDepartmentByIds(ids,{
					callback:function(f){alert("删除成功");reload();},
					exceptionHandler:function(message){alert("删除失败，请重试");},
					errorHander:function(err){}
				})
			}
		}
	}

	function editDepts(){
		var objs = document.getElementsByName("id");	
		var ids=0;
		var vas='';
		for(var i=0;i<objs.length;i++){
			if(objs[i].checked){
				ids++;
				vas=objs[i].value;			
			}
		}
		if(ids!=1){
			alert("请选择一条且只能选择一条信息进行编辑！");
			return ;
		}	
		if(vas==''){
			alert("请先选择要操作的信息");
			return ;
		}else{
			editDept(vas);
		}	
	}
	function submitDept(){
		var dept={
			id:		$('dpId0').value,
			deptName:	$('deptName0').value,
			detail:	$('detail0').value,
			orderNo: $('orderNo0').value
		}
		WIN.close();
		WIN.showpg();
		deptService.editDepartment(dept,{
			callback:function(f){WIN.closepg();alert("操作成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
			errorHander:function(err){}
		})
	}
	
	</script>
</body>
</html>
